<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class company_model extends CI_Model
{
	public function get_user_companies($userID) {
        $this->db->select('
        	company.company_id,
        	company.company_name,
        	company.city,
        	company.state,
        	company.industry,
                user_company.user_id,
                user_company.user_company_id,
                user_company.company_id,
        	state.state_name as state
        ');

        $this->db->join('company', 'company.company_id = user_company.company_id');
        $this->db->join('state', 'state.state_id = company.state');
        $query = $this->db->get_where('user_company', array('user_id' => $userID));
        
        if ($query->num_rows() < 1) return FALSE;
        return $query->result_array();
	}

	public function get_company_details($companyID) {
        $this->db->join('state', 'state.state_id = company.state');
        $query = $this->db->get_where('company', array('company_id' => $companyID));
        
        if ($query->num_rows() != 1) return FALSE;
        return $query->row_array();
	}

	public function search_companies($searchTerm) {
        $this->db->select('
        	company.company_id,
        	company.company_name,
        	company.city,
        	company.state,
        	company.industry,
        	state.state_name as state
        ');

        $this->db->join('state', 'state.state_id = company.state');
        $this->db->like('company.company_name', $searchTerm);
        $query = $this->db->get_where('company');
        
        if ($query->num_rows() < 1) return FALSE;
        return $query->result_array();		
	}
}